Skip to content

Fix Python numerical derivatives for scalar inputs - #2932

Draft
yunyv wants to merge 2 commits into
borglab:developfrom
yunyv:fix/python-scalar-numerical-derivatives
Draft

yunyv wants to merge 2 commits into
borglab:developfrom
yunyv:fix/python-scalar-numerical-derivatives

Conversation

@yunyv

@yunyv yunyv commented Nov 12, 2026

Copy link
Copy Markdown

numericalDerivative11(lambda x: x ** 2, 3.0) fails because retract promotes the scalar input to a one-element array, and local rejects the resulting type mismatch. NumPy scalar inputs such as np.float32 and np.int64 also fall through to an unavailable .retract method. The existing scalar test uses a one-element array, so it does not cover these cases.

Keep scalar perturbations scalar, using double precision consistently with local, and permit mixed numeric scalar types when computing local coordinates. Array and manifold behavior is unchanged, including rejecting array/scalar mismatches. This does not preserve the input scalar dtype or arbitrary precision.

Tests cover Python float/int and NumPy float32/float64/int64 at zero, negative and positive values, mixed scalar local coordinates, scalar-only callbacks, and vector-valued residuals.

Validation:

  • New tests against the original module: 37 failed, 9 passed, 7 subtests passed.
  • Fixed focused suite: 11 passed, 42 subtests passed.
  • Related Pose3, NavState, Gal3 and ExtendedPose3 suites together: 34 passed, 42 subtests passed.
  • git diff --check passes. Ruff has only three pre-existing findings in these files (F841, UP035 and I001); no new findings remain.

Python tests use the current source utility with native bindings from the official gtsam-develop 4.3.2.dev202611100512 wheel. No C++ or MATLAB build was run, and no bindings were changed.

This change was prepared and tested with AI assistance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant